<template>
  <div class="page">
    <el-container>
      <!-- 侧边栏导航菜单 -->
      <el-aside width="260px">
        <div class="logo">Mtime</div>
        <el-menu class="el-menu" background-color="#00000000" text-color="#ffffffff">
          <el-submenu v-for="(groupItem,i) in menus" :key="groupItem.groupCode" class="el-submenu" :index="i"
            background-color="#00000000" text-color="#ffffffff" style="text-align: left;">
            <template slot="title">
              <i class="el-icon-menu" style="color:#fff;"></i>
              <span>{{groupItem.groupName}}</span>
            </template>
            <el-menu-item-group class="el-submenu">
              <el-menu-item :index="i+'-'+j" v-for="(menuItem,j) in groupItem.items" :key="menuItem.id"
                @click="menuClick(menuItem)">
                {{menuItem.menuName}}
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="exit" background-color="#00000000" text-color="#ffffffff" style="text-align: left;">
            <template slot="title">
              <i class="el-icon-close" style="color:#fff;"></i>
              <span @click="gotoLogin()">退出登录</span>
            </template>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <!-- 导航面包屑 -->
          <el-breadcrumb separator-class="el-icon-arrow-right" v-if="this.$router.currentRoute.path !== '/home'">
            <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{this.$router.currentRoute.name}}</el-breadcrumb-item>
          </el-breadcrumb>
          <div class="title" v-else>影片库管理系统</div>
          <div class="user right">当前登录：admin</div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
        <el-footer>
          <div class="text">企业级开发技术-WEB客户端开发技术课程案例-实验15 ©NIIT-SCS</div>
        </el-footer>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data () {
    return {
      //菜单数组
      menus: [],
      currentUser: ""
    }
  },
  methods: {
    gotoLogin () {
      localStorage.clear();
      this.$router.push("/login");
    },
    async loadMenus () {
      let res = await this.$api.menu.getMenu().catch(error => {
        this.$message.error("获取菜单失败", error);
      })
      this.menus = res.data
      console.log(this.menu);
    },
    menuClick (menu) {
      console.log("菜单点击", menu);
      this.$router.push('/admin/' + menu.href);
    }
  },
  mounted () {
    this.currentUser = localStorage.getItem("usertoken");
    this.loadMenus();
  }
}
</script>

<style scoped="scoped">
.page {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.el-header,
.el-footer {
  background-color: #fff;

  color: #999;
  line-height: 60px;
  display: flex;
}

.el-header {
  border-bottom: 0.6px solid rgba(99, 99, 99, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
}

.el-footer {
  border-top: 0.6px solid rgba(99, 99, 99, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
}

.el-aside {
  background: #304156;
  color: #fff;
  text-align: center;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  height: calc(100vh - 120px);
}

.logo {
  font-size: 230%;
  font-weight: 600;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 60px;
  width: 96%;
  border-bottom: 0.5px solid rgba(200, 200, 200, 0.7);
}

.title {
  font-size: 110%;
  margin-left: 30px;
}

.right {
  flex: 1;
  text-align: right;
  padding-right: 20px;
}
</style>
